package com.imooc.poker_game_v2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Player implements Comparable<Player> {
	private int id; // 玩家ID
	private String name; // 玩家名称
	private Card maxCard; // 手里最大的牌
	private List<Card> cards = new ArrayList<Card>(); // 手里所有的牌
	
	public Player(int id, String name) {
		this.id = id;
		this.name = name;
	}
	
	public int getId() {
		return id;
	}
	
	public String getName() {
		return name;
	}
	
	public List<Card> getCards() {
		return cards;
	}
	
	public Card getMaxCard() {
		if (this.maxCard == null) {
			// 找到最大的牌
			Collections.sort(cards);
			this.maxCard = cards.get(0);
		}
		return maxCard;
	}
	
	@Override
	public int compareTo(Player o) {
		return this.getMaxCard().compareTo(o.getMaxCard());
	}
	
	/**
	 * 增加新牌
	 * 
	 * @param card
	 */
	public void add(Card card) {
		System.out.println("--玩家[" + this.getName() + "]拿牌: " + card);
		this.cards.add(card);
	}
	
	/**
	 * 打印玩家最大的手牌
	 */
	public void showMaxCard() {
		System.out.println("玩家[" + this.getName() + "]最大的手牌为: " + this.getMaxCard());
	}
	
	
	/**
	 * 打印玩家各自手牌 
	 */
	public void showCards() {
		System.out.println(this.getName() + " : " + getCards());
	}
	
}
